<!doctype html>

<html>

  <head>
    <meta charset="utf-8">
    <title>Simple logging example 2: text logging</title>
  </head>

  <body>
    <script>
      const memory = new WebAssembly.Memory({ initial: 1 });

      function consoleLogString(offset, length) {
        const bytes = new Uint8Array(memory.buffer, offset, length);
        const string = new TextDecoder("UTF-8").decode(bytes);
        console.log(string);
      }

      const importObject = {
        console: {
          log: consoleLogString
        },
        js: {
          mem: memory
        }
      };

      WebAssembly.instantiateStreaming(fetch("logger2.wasm"), importObject)
      .then(obj => {
        obj.instance.exports.writeHi();
      });
    </script>
  </body>

</html>
